<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="commontaglib"%>
<%@ page import="hibernate.VGlUserinfo"%>
<%@ page import="com.opensymphony.xwork2.ActionContext"%>
<%@ page import="com.ctctc.business.BusinessConfiguration"%>
<%@ page import="java.util.*"%>
<%
	VGlUserinfo user = (VGlUserinfo) session.getAttribute(BusinessConfiguration.SESSION_USERNAME);
	String role = user.getRoleid();
    String path = request.getContextPath();  
    String jiaoylx = request.getParameter("jiaoylx");
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
 
<html>
  <head>
    <link rel="stylesheet" href="<%=path%>/css/innerstyle.css" type="text/css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<%=path%>/css/cupertino/jquery-ui.custom.min.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<%=path%>/css/ui.jqgrid.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<%=path%>/css/ui.multiselect.css" />
    <script type="text/javascript" src="<%=path%>/js/jquery-1.7.2.min.js"></script>

     <script type="text/javascript" src="<%=path%>/js/jquery-ui.custom.min.js"></script> 

    <script type="text/javascript" src="<%=path%>/js/i18n/grid.locale-cn.js"></script> 
    <script type="text/javascript" src="<%=path%>/js/jquery.jqGrid.min.js"></script>
    <script type="text/javascript" src="<%=path%>/js/i18n/jquery.ui.datepicker-zh-CN.js"></script>
    <script type="text/javascript" src="<%=path%>/js/json2.js"></script>
     <style>
html, body {
	margin: 0;			 
	padding: 0;
	 
    font-size: 85%;
}
</style>
    <script>
    var qieye = 0;
   
	$(function() {
	   loadTab(0);	   
	   queryNum();
	   $("#chax").button();
	   $("#excel1").button(); 
	   $("#reset").button();
	   $("#excel2").button();
	   $( "#datepicker" ).datepicker($.datepicker.regional[ "zh-CN" ]);
       $( "#datepicker1" ).datepicker($.datepicker.regional[ "zh-CN" ]);
       $( "#zidqysj" ).datepicker($.datepicker.regional[ "zh-CN" ]); 
       $( "#zidqysj1" ).datepicker($.datepicker.regional[ "zh-CN" ]);     
	   $( "#tabs" ).tabs({
		    select: function(event, ui) {
		   
		    var i =ui.index;		        
		    if(i==''){
		    i=0;
		    $("#zhuangt").val(-1);
		    }
		    else if(i=='1')
		    {
		     $("#zhuangt").val(1);
		    }
		     else if(i=='2')
		    {
		     $("#zhuangt").val(2);
		    }
		     else if(i=='3')
		    {
		     $("#zhuangt").val(5);
		    }
		     else if(i=='4')
		    {
		     $("#zhuangt").val(6);
		    }
		    qieye = i;
		    loadTab(i);  
		      queryNum();   
            //return false;
    }
		
		});
		 
         
	});
	
	 function loadTab(i){ 	  
    $("#myTab"+i).jqGrid({      
    url:'htcxJqgrid.action?index='+i+'&jiaoylx='+<%=jiaoylx%>,   
    datatype: 'json',
    mtype: 'post',         
   	colNames:['合同号', '出卖人','发货单位名称', '买受人','收货单位','煤种','品种','价格','数量','合同总价','签订日期','合同状态',],
   	colModel:[ 
   	    //{name:'chak',index:'hetbh',width:40,align:"center",sortable:false},	  		
   		{name:'hetlrbh',index:'hetlrbh', width:120},
   		{name:'chumdwmc',index:'chumdwmc', width:120},
   		{name:'fahdwmc',index:'fahdwmc', width:120},
   		{name:'maisdwmc',index:'maisdwmc', width:120 },
   		{name:'shouhdwmc',index:'shouhdwmc', width:120 },
   		{name:'meiz',index:'meiz', width:60 },	
   		{name:'pinz',index:'pinz', width:60 },	
   		{name:'jiag',index:'jiag', width:60 },
   		{name:'shul',index:'shul', width:60 },
   		{name:'htzj',index:'htzj', width:60 },
   		{name:'qianysj',index:'qianysj', width:80},	
   		{name:'htzt',index:'htzt', width:50}		
   	],
   
    jsonReader: {
           repeatitems : false, 
           id: 'hetbh'
         },    	
   	rowNum:10,
   	rowList:[10,20,30],     	
   	pager: '#pager'+i,
   	rownumbers: true,   	 
    viewrecords: true,
    sortorder: 'desc',
	//loadonce:true,
	//altRows:true,
    multiselect: true,  
	//caption: "合同列表"	
	ondblClickRow: function(rowid){
	    //var id = $("#myTab"+i).jqGrid('getGridParam', 'selarrrow');
        //alert(id);
        openwindow('<%=path %>/htgl/htcxInfo.action?htbh='+rowid); 
	},
	//gridComplete:function()
	//{ //在此事件中循环为每一行添加修改和删除链接 	
		//var ids=$("#myTab"+i).jqGrid('getDataIDs'); 
		//alert(ids);
		//for(var j=0; j<ids.length; j++)
		//{		
		//     hth=ids[j];
		//	 verify="<div style='color:#f60'>查看</div>";
		//	$("#myTab"+i).jqGrid('setRowData',hth, { chak: verify }); 
			
		//}
	//}
  });
   if(<%=role%>=='20'){
   $("#myTab"+i).jqGrid('hideCol',["chumdwmc"]);
   }else{
   $("#myTab"+i).jqGrid('hideCol',["maisdwmc"]);
   }
   $("#myTab"+i).jqGrid('setGridHeight','240px');
   
  }
  
  // 查询
function search(){  
  var formdata = $("#form1").serialize(); 
  $("#myTab"+qieye).jqGrid('setGridParam',{url:'htcxJqgrid.action?'+formdata+'&jiaoylx='+<%=jiaoylx%>+'&index='+qieye,mtype:'post',page:1}).trigger("reloadGrid"); 
}



 function openwindow(url){
    var sheight = screen.height-30;
    var swidth = screen.width-1;
    var winoption ="height="+sheight+"px,width="+ swidth +"px,toolbar=no,menubar=no,scrollbars=yes, resizable=yes,location=yes,status=yes";
    var result=window.open(url,"newwindow",winoption);
    if(result ==1) window.location.reload(); 
    return result;  
}

//重置
function resetSearch(){
	$('#list_search  input[type=text]').val('');
	$('#list_search select').val('-1');
}
       // 批量导出excel
function excel_pl(){ 
	form1.action="<%=path%>/htgl/jytj_excel.action?index="+qieye+"&jiaoylx="+<%=jiaoylx%>;
	form1.method = "post";
	form1.submit();
	}
	// 样本导出excel
function excel_yb(){ 
    var hetbh =null;
	hetbh = jQuery("#myTab"+qieye).jqGrid('getGridParam','selarrrow');
	if(hetbh.length!=1)
    {
    //警告
      $( "#jinggao" ).dialog({
			resizable: false,
			height:140,
			modal: true,
			buttons: {
				"确认": function() {
					$( this ).dialog( "close" );
				}
			}
		});
    }
   
	else
	{
	window.location.href="<%=path%>/report1/htexcel.action?hetbh="+hetbh;
	}	
	}
	
	//计算成交金额函数
		function queryNum(){   
			  var formdata = $("#form1").serialize(); 
			  //alert(formdata);
			  $.post("<%=path%>/htgl/queryNum.action?jiaoylx="+<%=jiaoylx%>+"&index="+qieye+"&",formdata,function(data,textStatus)
			  {
			  
			  var json = eval('(' + data + ')');
			
			  var re=/(\d{1,3})(?=(\d{3})+(?:$|\.))/g;
	if (json[0].zongsl !="")
{
			   $("#queryNum").html("价格范围："+json[0].zongjg + "元/吨  总数量："+json[0].zongsl.toString().replace(re,"$1,")+"吨  总金额："+json[0].zongje.toString().replace(re,"$1,")+"元");
			} else{
			 $("#queryNum").html("价格范围：0  元/吨  总数量：0 吨  总金额：0 元");
			 } });
  
               }
	</script>
    
  </head>
  <body>
  <div id="best1">
   <p></p>
   <form id="form1" method="post">
   <table id="list_search" cellpadding="0" cellspacing="0" border="0"> 
        <tr>
        	<td> 
            	合同编号: 
            </td>
            <td>
            	<input type="text" class="longtextbox" name="bean.AA" /> 
            </td>
            <td>
                                       煤种:
            </td>
            <td>
            	<div class="select"><div><s:select name="bean.BB" headerKey="-1" headerValue="请选择"  list="mzList" listKey="diccode" listValue="dicname" id="combobox"/></div></div> 
            </td>            
            <td>
                                      品种 :
            </td>
            <td>
            	<div class="select"><div><s:select name="bean.CC" headerKey="-1" headerValue="请选择"  list="pzList" listKey="diccode" listValue="dicname" /></div></div>
            </td>
        </tr>
        
        <tr>
        <td>出卖人:</td>
        <td><input type="text" class="longtextbox" name="bean.DD" /></td>
        <td>发货单位:</td>
        <td><input type="text" class="longtextbox" name="bean.EE" /></td>
        <td>出省站/营业站:</td>
        <td><input type="text" class="longtextbox" name="bean.FF" /></td>
        </tr>
        
        
        <tr>
        <td>买受人:</td>
        <td><input type="text" class="longtextbox" name="bean.GG" /></td>
        <td>收货单位:</td>
        <td><input type="text" class="longtextbox" name="bean.HH" /></td>
        <td>到达省/市:</td>
        <td><input type="text" class="longtextbox" name="bean.II" /></td>
        </tr>
        
        
        <tr>
        <td>价格:</td>
        <td><input type="text" class="textboxs" name="bean.JJ" onKeyUp="this.value=this.value.replace(/\D/g,'');" />
          --
          <input type="text" class="textboxs" name="bean.KK" onKeyUp="this.value=this.value.replace(/\D/g,'');" /></td>
        <td>数量:</td>
        <td><input type="text" class="textboxs" name="bean.LL" onKeyUp="this.value=this.value.replace(/\D/g,'');" />
          --
          <input type="text" class="textboxs" name="bean.MM" onKeyUp="this.value=this.value.replace(/\D/g,'');" /></td>
        <td>签订日期:</td>
            <td>
            	<input id="datepicker" type="text" class="textboxs" name="bean.NN" /> -- <input id="datepicker1" type="text" class="textboxs" name="bean.OO" />
            </td>
        </tr>
        
        
        <tr>
        <td>合同形式:</td>
        <td><div class="select"><div><s:select name="bean.PP" headerKey="-1" headerValue="请选择"  list="htxsList" listKey="diccode" listValue="dicname" /></div></div></td>        
        <td>隶属行业:</td>
        <td><div class="select"><div><s:select name="bean.RR" headerKey="-1" headerValue="请选择"  list="hyList" listKey="diccode" listValue="dicname" /></div></div></td>
        <td><input type="hidden" class="longtextbox" name="bean.QQ" id="zhuangt"  value="-1"/>确认时间:</td><td><input id="zidqysj" type="text" class="textboxs" name="bean.SS" /> -- <input id="zidqysj1" type="text" class="textboxs" name="bean.TT" /></td>
        
        
       
        </tr> 
        
               
		<tr>    			
            <td colspan="6" style="float:left"><input  id="excel1" type="button" value="全部信息导出excel" onclick="excel_pl();" /></td>
            <td colspan="6" style="float:left"><input  id="excel2" type="button" value="合同样本导出excel" onclick="excel_yb();" /></td>         
            <td colspan="6" style="float:right"><input id="chax" type="button" value="查询" onclick="search();queryNum();"/></td> 
            <td colspan="6" style="float:right"><input id="reset" type="button" value="重置" onclick="resetSearch();"/></td>         
        </tr>
        
        
  </table> 
  </form>
     
     				
     
    <div id="tabs">
	<ul>
		<li><a href="#tabs-0">全部</a></li>
		<li><a href="#tabs-1">待应单</a></li>
		<li><a href="#tabs-2">待确认</a></li>
		<li><a href="#tabs-3">已归档</a></li>
		<li><a href="#tabs-4">已退回</a></li>	
		<li id="queryNum"  style="float:right; vertical-align: bottom; line-height:20px; top: 3px;"></li>	
	</ul>
	<div id="tabs-0">  
		<table id="myTab0" class="scroll" cellpadding="0" cellspacing="0"></table>
		<div id="pager0" class="scroll"></div>  
        <div id="message0" class="scroll"></div> 
	</div>	
	<div id="tabs-1">  
		<table id="myTab1" class="scroll" cellpadding="0" cellspacing="0"></table>
		<div id="pager1" class="scroll"></div>  
        <div id="message1" class="scroll"></div> 
	</div>
	<div id="tabs-2">  
		<table id="myTab2" class="scroll" cellpadding="0" cellspacing="0"></table>
		<div id="pager2" class="scroll"></div>  
        <div id="message2" class="scroll"></div> 
	</div>
	<div id="tabs-3">  
		<table id="myTab3" class="scroll" cellpadding="0" cellspacing="0"></table>
		<div id="pager3" class="scroll"></div>  
        <div id="message3" class="scroll"></div> 
	</div>
	<div id="tabs-4">  
		<table id="myTab4" class="scroll" cellpadding="0" cellspacing="0"></table>
		<div id="pager4" class="scroll"></div>  
        <div id="message4" class="scroll"></div>  
	</div>
</div>
<div id="jinggao" title="警告:请选择一条合同"></div>
</div>


  </body>
</html>
